package implementation;

import protocol.Query;
import protocol.SessionManager;
import protocol.StateObject;

public class SessionManagerImpl implements SessionManager {
	private StateObject nextState;
	private Query query;
	
	public SessionManagerImpl()
	{
		nextState = new StateObject();
	}
	
	@Override
	public void doSession() {
		boolean sessionTerminated = false;
		while( !sessionTerminated ){
			switch(nextState.getState()){
			case GREETING:
				handleGreeting();
				break;
			case NUMTIX:
				query = new Query();
				handleNumTix();
				break;
			case HOMETEAM:
				handleHomeTeam();
				//sessionTerminated = true;
				break;
			case AWAYTEAM:
				handleAwayTeam();
				break;
			case AWAYTEAMCONF:
				handleAwayTeamConf();
				break;
			case DATE:
				handleDate();
				break;
			case PRICE:
				handlePrice();
				break;
			case RECAP:
				handleRecap();
				break;
			case CLOSING:
				sessionTerminated  = handleClosing();
				break;
			}
		}
	}

	@Override
	public void handleGreeting() {
		GreetingHandler.handleGreeting(nextState);
	}

	@Override
	public void handleNumTix() {
		NumTixHandler.handleNumTix(nextState, query);
	}

	@Override
	public void handleHomeTeam() {
		HomeTeamHandler.handleHomeTeam(nextState, query);
	}

	@Override
	public void handleAwayTeam() {
		AwayTeamHandler.handleAwayTeam(nextState, query);
	}
	
	@Override
	public void handleAwayTeamConf() {
		AwayTeamConfHandler.handleAwayTeamConf(nextState, query);	
	}

	@Override
	public void handleDate() {
		DateHandler.handleDate(nextState, query);
	}

	@Override
	public void handlePrice() {
		PriceHandler.handlePrice(nextState, query);
	}

	@Override
	public void handleRecap() {
		RecapHandler.handleRecap(nextState, query);
	}

	@Override
	public boolean handleClosing() {
		return ClosingHandler.handleClosing(nextState, query);
	}

}
